<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">通用大数据框架智能计算引擎优化仿真平台</el-breadcrumb-item>
      <el-breadcrumb-item>计算任务</el-breadcrumb-item>
      <el-breadcrumb-item>容器方案管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query"  class="input-with-select" clearable>
            <el-button slot="append" icon="el-icon-search" @click="getContainerList" ></el-button>
          </el-input>

        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addContainer" >创建容器方案</el-button>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addComputingtask" >创建计算任务</el-button>
        </el-col>
      </el-row>
      <el-table
          :data = "ContainerList"
          border
          style="width: 100%">
        <el-table-column
            prop="containerschemename"
            label="容器名称"
            width="200">
        </el-table-column>
        <el-table-column
            prop="containerschemenametype"
            label="容器类别"
            width="180">
        </el-table-column>
        <el-table-column
            prop="createtime"
            label="创建时间"
            width="200">
        </el-table-column>
        <el-table-column
            prop="createman"
            label="创建人"
            width="200">
        </el-table-column>
        <el-table-column
            prop="operate"
            label="操作"
            width="360">
          <template >
            <el-tooltip class="item" effect="dark" content="编辑" placement="top">
              <el-button type="primary" icon="el-icon-edit"  @click="editContainerScheme(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="top">
              <el-button type="danger" icon="el-icon-delete" @click="removeContainerScheme(scope.row)" ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @size-change="SizeChange"
          @current-change="CurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[10,20,30]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>

    </el-card>
    <el-dialog
        title="创建计算"
        :visible.sync="addContainerVisble"
        width="20%"
        @close="closeaddContainerDialog"
    >
      <el-form :model="addContainerForm" :rules="addContainerFormRul" ref="addContainerFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="容器方案名称" prop="addContainername">
          <el-input v-model="addContainerForm.addContainername"></el-input>
        </el-form-item>
        <el-form-item label="选择容器"  >

          <el-select v-model="addContainerForm.checkedcontainer" prop="checkedcontainer" placeholder="请选择" :multiple = true :filterable="true">
            <el-option
                v-for="item in container"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="addContainerVisble = false">取 消</el-button>
     <el-button type="primary" @click="addContainersubmit">确 定</el-button>
     </span>
    </el-dialog>
    <el-dialog
        title="创建计算任务"
        :visible.sync="addComputingtaskVisble"
        width="20%"
        @close="closeaddComputingtaskDialog"
    >
      <el-form :model="addComputingtaskForm" :rules="addComputingtaskFormRul" ref="addComputingtaskFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="计算任务名称" prop="addComputingtaskname">
          <el-input v-model="addComputingtaskForm.addComputingtaskname"></el-input>
        </el-form-item>
        <el-form-item label="选择容器方案"  >

          <el-select v-model="addComputingtaskForm.checkedcontainerscheme" prop="checkedcontainerscheme" placeholder="请选择" :multiple = true :filterable="true">
            <el-option
                v-for="item in containerscheme"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择计算方案"  >

          <el-select v-model="addComputingtaskForm.checkedcalculationscheme" prop="checkedcalculationscheme" placeholder="请选择" :multiple = true :filterable="true">
            <el-option
                v-for="item in calculationscheme"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择优化方案"  >

          <el-select v-model="addComputingtaskForm.checkedoptimizationscheme" prop="checkedoptimizationscheme" placeholder="请选择" :multiple = true :filterable="true">
            <el-option
                v-for="item in optimizationscheme"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="addComputingtaskVisble = false">取 消</el-button>
     <el-button type="primary" @click="addComputingtaskVisblesubmit">确 定</el-button>
     </span>
    </el-dialog>
    <el-dialog
        title="编辑文件"
        :visible.sync="editContainerSchemeVisble"
        width="30%"
        @close="closeeditContainerScheme"
    >

      <el-form :model=" editContainerSchemeParams"  :rules="editContainerSchemeFormRul" ref="editContainerSchemeParamsFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="文件名" prop="editContainerSchemeName" >
          <el-input v-model="editContainerSchemeParams.editContainerSchemeName"  ></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="editContainerSchemeVisble= false">取 消</el-button>
     <el-button type="primary" @click="editContainerSchemeSubmit">确 定</el-button>
     </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data(){
    return{
      ContainerList:[],
      queryInfo:{
        //查询参数
        query:'',
        pagenum:1,
        pagesize:10,

      },
      editContainerSchemeVisble:false,
      addComputingtaskForm:{
        addComputingtaskname:'',
        checkedcontainerscheme:[],
        checkedoptimizationscheme:[],
        checkedcalculationscheme:[]

      },
      editContainerSchemeFormRul:{},
      addComputingtaskFormRef:{},
      total:0,
      addContainerVisble:false,
      addComputingtaskVisble:false,
      addContainerForm:{
        addContainername:'',
        checkedontainer:[]
      },
      addContainerFormRul:{},
      addComputingtaskFormRul:{},
      checkedcontainer:[],
      checke:[],
      optimizationscheme:[],
      calculationscheme:[],
      containerscheme:[],
      container:[],
      optimizationschemetest:[
        {
          value:'1',
          label:'优化方案01'
        },
        {
          value:'2',
          label:'优化方案02'
        }
      ],
      calculationschemetest:[
        {
          value:'1',
          label:'计算方案01'
        },
        {
          value:'2',
          label:'计算方案02'
        }

      ],
      containerschemetest:[
          {
        value:'1',
        label:'容器方案01'
      },
    {
      value:'2',
          label:'容器方案02'
    }

      ],
      containertest:[
          {
        value:'1',
        label:'默认容器'
      },
        {
          value:'2',
          label:'图像容器'
        }],
      editContainerSchemeParams:{
        editContainerSchemeName:'',
      }
    }

  },
  methods:{
    closeaddContainerDialog(){
      this.$refs.addContainerFormRef.resetFields()

    },
    addContainer(){
      this.$http.get('/').then(res=>{
        if(res.data.meta.status !== 200)
            // return this.$message.error('获取信息失败')

            //将这里的files等替换成数据库里的
          this.container=this.containertest


      })

      this.addContainerVisble = true
    },
    closeeditContainerScheme(){
      this.$refs.editContainerSchemeParamsFormRef.resetFields()
    },
    addComputingtask(){
      this.$http.get('/').then(res=>{
        if(res.data.meta.status !== 200)
            // return this.$message.error('获取信息失败')

            //将这里的files等替换成数据库里的
          this.optimizationscheme = this.containertest
          this.calculationscheme = this.calculationschemetest
          this.containerscheme = this.containerschemetest
      })


      this.addComputingtaskVisble = true
    },
    SizeChange(newsize){
      this.queryInfo.pagesize = newsize
      this. getContainerList()
    },
    CurrentChange(newnumber){
      this.queryInfo.pagenum = newnumber
      this. getContainerList()
    },
    removeContainerScheme(row){
      this.$confirm('此操作将永久删除该文件', '是否继续?', '删除文件', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.delete(`/${row.ContainerSchemeid}`).then(res=>{
          if(res.data.meta.status !== 200) return this.$message.error('删除失败')
          this.$message.success('删除成功')
          this.getFileList()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getContainerList(){
      // this.$http.get('',{params:this.queryInfo}).then(res=>{
      //   if(res.data.meta.status !== 200)
      //     return this.$message.error('请求优化方案列表失败')
      //
      // })
      this.ContainerList = this.test
      this.total = 0
    },
    addContainersubmit(){
      this.$refs.addContainerFormRef.validate(valid=>{
        if(!valid) return alert('请输入正确信息')
      })
      this.$http.post('/',this.addContainerForm).then(res=>{
        console.log(res)

      })
      this.addContainerVisble = false
      this.checkedcontainer=this.check
      this.getContainerList()
    },
    closeaddComputingtaskDialog(){
      this.$refs.addComputingtaskFormRef.resetFields()
    },
    addComputingtaskVisblesubmit(){
      this.$refs.addComputingtaskFormRef.validate(valid=>{
        if(!valid) return alert('请输入正确信息')
      })
      this.$http.post('/',this.addComputingtaskForm).then(res=>{
        console.log(res)

      })
      this.addComputingtaskVisble = false
      this.getContainerList()
    },
    editContainerScheme(row){
      this.editContainerSchemeParams = row
      this.editContainerSchemeVisble = true
      // this.$http.get(`/${row.id}`).then(res=>{
      //   this.editFileParamse= res
      //
      //
      // })
    },
    editContainerSchemeSubmit(){
      this.$http.put(`/${this.editContainerSchemeParams.editContainerSchemeName}`,this. editContainerSchemeParams).then(res=>{
        if(res.data.meta.status !== 200) return this.$message.error('更新失败')
        this.getContainerList()
        this.editContainerSchemeVisble = false
      })
    }

  },
  created() {
    this.getContainerList()
  }
}
</script>
<style>

</style>
